# '''
# 该程序作用是使用 SPI / SoftSPI 在 OLED 屏幕上显示 Hello World
# 在线文档：https://docs.geeksman.com/esp32/MicroPython/13.esp32-micropython-spi-oled.html
# '''
from machine import Pin, SoftSPI,SoftI2C
from lib.ssd1306 import SSD1306_SPI
from lib.ssd1306 import SSD1306_I2C
# import lib.ssd1306


# 定义对应的管脚对象
# spi = SoftSPI(sck=Pin(22), mosi=Pin(21), miso=Pin(19))
# i2c = SoftI2C(sda=Pin(13), scl=Pin(14))
i2c = SoftI2C(sda=Pin(21), scl=Pin(22), freq=100000)

# 创建 OLED 对象
# oled = SSD1306_SPI(width=128, height=64, spi=spi, dc=Pin(2),
#                    res=Pin(15), cs=Pin(4))
display = SSD1306_I2C(128, 32, i2c )
 
# 清屏
oled.fill(0)
# oled.fill(1)
# 画点
# display.pixel(30, 30, 1)
# display.pixel(30, 31, 1)
# display.pixel(30, 32, 1)
# display.pixel(30, 33, 1)
# display.pixel(30, 34, 1)
# display.pixel(30, 35, 1)

# 画方块

# for x in range(10, 30):
#     for y in range(10, 30):
#         oled.pixel(x, y, 1)

# 打印 Hello world 在屏幕上
display.text('Frank!',10, 0)
# display.poweroff()     # power off the display, pixels persist in memory
# display.poweron()      # power on the display, pixels redrawn
# display.contrast(0)    # dim
# display.contrast(255)  # bright
# display.invert(1)      # display inverted
# display.invert(0)      # display normal
# display.rotate(True)   # rotate 180 degrees
# display.rotate(False)  # rotate 0 degrees
# display.show()         # write the contents of th
# # 显示内容

display.show()